package Thread;

/**
 * @author 王艺锡
 * @version 1.0
 * 多线程
 */
//在main线程启动两个子线程
//实现Runnable接口方式更加适合多个子线程共享一个资源的情况，并且避免了单线程继承的限制
public class Thread03 {
    public static void main(String[] args) {
        T1 t1 = new T1();
        T2 t2 = new T2();
        Thread thread = new Thread(t1);
        thread.start();
        Thread thread1 = new Thread(t2);
        thread1.start();
    }
}
@SuppressWarnings({"all"})
class T1 implements Runnable{
    int count = 0;
    @Override
    public void run() {
    //每隔一秒输出hello，你好!
        while (count < 10){
            System.out.println("嗨,你好!" + "_" + ++count);

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

class T2 implements Runnable{
    int count = 0;
    @Override
    public void run() {
        //每隔一秒输出hello，你好!
        while (count < 5){
            System.out.println("他妈的家都没了，还在这嗨~你好~" + "_" + ++count);

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}